<template>
    <div>
        <el-dialog :title="title" :visible.sync="centerDialogVisible" width="30%" @close="close" center>
            <div>
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="项目全称" prop="fullName">
                        <el-input v-model.trim="ruleForm.fullName" placeholder="请输入项目全称"></el-input>
                    </el-form-item>
                    <el-form-item label="项目简称" prop="name">
                        <el-input v-model.trim="ruleForm.name" placeholder="请输入项目简称"></el-input>
                    </el-form-item>
                    <el-form-item label="合同单位" prop="contractUnit">
                        <el-input v-model.trim="ruleForm.contractUnit" placeholder="请输入合同单位"></el-input>
                    </el-form-item>
                    <el-form-item label="主体单位" prop="mainUnit">
                        <el-input v-model.trim="ruleForm.mainUnit" placeholder="请输入主体单位"></el-input>
                    </el-form-item>
                    <el-form-item label="项目类型" prop="projectType">
                        <el-select v-model="ruleForm.projectType" placeholder="请选择项目类型">
                            <el-option v-for="item in projectTypeList" :key="item.value" :label="item.label"
                                :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="handleSaveClick">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { setPrjFormal } from "@/service/Api";

export default {
    name: "regularizationDialog",
    data() {
        return {
            title: "",
            centerDialogVisible: false,
            textFlag: true,
            messageSource_text: "",
            ruleForm: {
                id: "",
                fullName: "", //项目全称
                name: "", //项目简称
                contractUnit: "", //合同单位
                mainUnit: "", //主体单位
                projectType: "",//项目类型
            },
            rules: {
                fullName: [
                    {
                        required: true,
                        message: "请输入项目全称",
                        trigger: "blur",
                    },
                ],
                name: [
                    {
                        required: true,
                        message: "请输入项目简称",
                        trigger: "blur",
                    },
                ],
                contractUnit: [
                    {
                        required: true,
                        message: "请输入合同单位",
                        trigger: "blur",
                    },
                ],
                mainUnit: [
                    {
                        required: true,
                        message: "请输入主体单位",
                        trigger: "blur",
                    },
                ],
                projectType: [
                    {
                        required: true,
                        message: "请选择项目类型",
                        trigger: "change",
                    },
                ],
            },
            projectTypeList: [
                {
                    value: 1,
                    label: "管理类",
                },
                {
                    value: 2,
                    label: "自研产品",
                },
                {
                    value: 3,
                    label: "委托开发",
                },
                {
                    value: 4,
                    label: "市场",
                },
            ], //项目类型：1、管理类 2、自研产品 3、委托开发 4、市场
        };
    },
    created() { },
    methods: {
        showDialog(row = null) {
            this.centerDialogVisible = true;
            this.title = "转为正式项目";
            this.ruleForm.id = row.id;
            this.ruleForm.projectType = row.projectType;
            this.$nextTick(() => {
                this.resetForm("ruleForm");
                this.messageSource_text = "";
            });
        },
        close() {
            this.centerDialogVisible = false;
        },
        handleSaveClick() {
            this.submitForm("ruleForm");
        },
        submitForm(formName) {
            // const data = {
            //     id: this.ruleForm.id,
            //     fullName: this.ruleForm.fullName,
            //     name: this.ruleForm.name,
            //     contractUnit: this.ruleForm.contractUnit,
            //     mainUnit: this.ruleForm.mainUnit,
            //     projectType: this.ruleForm.projectType,
            // };
            // setPrjFormal(data).then((response) => {
            //     if (response.code === 0) {
            //         this.$message.success("操作成功");
            //         this.close();
            //         this.$refs.first.refresh();
            //     }
            // });
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$emit("dialogResults", this.ruleForm);
                    this.close();
                } else {
                    console.log("error submit!!");
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
    },
};
</script>
